package cn.yh.register.hosp.api;


import cn.yh.register.common.result.Result;
import cn.yh.register.hosp.service.DepartmentService;
import cn.yh.register.hosp.service.HospitalService;
import cn.yh.register.hosp.service.HospitalSetService;
import cn.yh.register.hosp.service.ScheduleService;
import cn.yh.register.model.hosp.Hospital;
import cn.yh.register.model.hosp.Schedule;
import cn.yh.register.vo.hosp.DepartmentVo;
import cn.yh.register.vo.hosp.HospitalQueryVo;
import cn.yh.register.vo.hosp.ScheduleOrderVo;
import cn.yh.register.vo.order.SignInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.naming.spi.DirStateFactory;
import java.util.List;
import java.util.Map;

/**
 * 用户前端调用的接口
 */
@Api(tags = "医院管理接口")
@RestController
@RequestMapping("/api/hosp/hospital")
public class HospitalApiController {


    @Autowired
    private HospitalService hospitalService;

    @Autowired
    private DepartmentService departmentService;

    @Autowired
    private ScheduleService scheduleService;

    @Autowired
    private HospitalSetService setService;

    @ApiOperation(value = "获取分页列表")
    @GetMapping("{page}/{limit}")
    public Result<Page<Hospital>> findHospListPage(@PathVariable Integer page,
                                     @PathVariable Integer limit,
                                     HospitalQueryVo hospitalQueryVo){
        Page<Hospital> pageList = hospitalService.findPageList(hospitalQueryVo, page, limit);
        return Result.ok(pageList);
    }

    @ApiOperation(value = "根据医院名称获取医院列表")
    @GetMapping("findByHosname/{hosname}")
    public Result<List<Hospital>> findByHosnameLike(@PathVariable String hosname){
        List<Hospital> hosNameList = hospitalService.findByHosNameList(hosname);
        return Result.ok(hosNameList);
    }

    @ApiOperation(value = "根据医院编号获取医院详细信息")
    @GetMapping("/{hoscode}")
    public Result<Map<String, Object>> findByHosCodeInfo(@PathVariable String hoscode){
        Map<String, Object> map = hospitalService.findByHosCodeInfo(hoscode);
        return Result.ok(map);
    }

    @ApiOperation("用户端树形展示科室信息")
    @GetMapping("/department/{hoscode}")
    public Result<List<DepartmentVo>> findInfoByTree(@PathVariable String hoscode){
        List<DepartmentVo> voList = departmentService.findDepartmentTree(hoscode);
        return Result.ok(voList);
    }

    @ApiOperation(value = "获取可预约的排班数据")
    @GetMapping("/auth/getBookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
    public Result<Map<String, Object>> getBookingSchedule(@PathVariable Integer page,
                                       @PathVariable Integer limit,
                                       @PathVariable String hoscode,
                                       @PathVariable String depcode){
        Map<String, Object> map = scheduleService.getBookingScheduleRule(page, limit, hoscode, depcode);
        return Result.ok(map);
    }

    @ApiOperation("获取某天的排班详情")
    @GetMapping("/auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
    public Result<List<Schedule>> getDetailSchedule(@PathVariable String hoscode,@PathVariable String depcode, @PathVariable String workDate){
        List<Schedule> scheduleList = scheduleService.getDetailSchedule(hoscode, depcode, workDate);
        return Result.ok(scheduleList);
    }

    @ApiOperation(value = "根据排班id获取排班数据")
    @GetMapping("getSchedule/{scheduleId}")
    public Result<Schedule> getSchedule(@PathVariable String scheduleId){
        Schedule schedule = scheduleService.getSchedule(scheduleId);
        return Result.ok(schedule);
    }

    @ApiOperation(value = "获取订单上的排班数据")
    @GetMapping("inner/getScheduleOrderVo/{scheduleId}")
    public ScheduleOrderVo getScheduleOrderVo(@PathVariable String scheduleId){
        return scheduleService.getScheduleOrderVo(scheduleId);
    }

    @ApiOperation(value = "获取医院签名信息")
    @GetMapping("inner/getSignInfoVo/{hoscode}")
    public SignInfoVo getSignInfoVo(@PathVariable String hoscode){
        return setService.getSignInfoVo(hoscode);
    }
}
